package sii.fb.emotion.computProbability;

import java.text.SimpleDateFormat;
import java.util.List;
import java.util.Map;

import sii.fb.emotion.Main;
import sii.fb.emotion.bean.Post;
import sii.fb.emotion.bean.User;

public class ProbabilityBasedOnAge {
	//ListEmotion based on age
		public  void age2Emotion(Map<Long, User> users, Map<Long, List<Post>> posts){
			SupportMethod cp = new SupportMethod();
			User u;
			Float[] emo_less21 = new Float[]{0F,0F,0F,0F,0F,0F,0F,0F,0F,0F,0F};
			Float[] emo_21to30 = new Float[]{0F,0F,0F,0F,0F,0F,0F,0F,0F,0F,0F};
			Float[] emo_31to40 = new Float[]{0F,0F,0F,0F,0F,0F,0F,0F,0F,0F,0F};
			Float[] emo_41to50 = new Float[]{0F,0F,0F,0F,0F,0F,0F,0F,0F,0F,0F};
			Float[] emo_more50 = new Float[]{0F,0F,0F,0F,0F,0F,0F,0F,0F,0F,0F};

			int post_less21 = 0;
			int post_21to30 = 0;
			int post_31to40 = 0;
			int post_41to50 = 0;
			int post_more50 = 0;
			int age;
			for(Long l:posts.keySet()){
				u = users.get(l);
				if(u.getBirtday()!=null){
				age = 2014 - Integer.parseInt(new SimpleDateFormat("yyyy").format(u.getBirtday()));
				List<Post> post = posts.get(l);
				for(Post p: post){
					float[] emotionPost = p.getEmotion();
					if(age<21){
						post_less21++;
						cp.updateEmotionArray(emotionPost, emo_less21);
					}else if(age<31){
						post_21to30++;
						cp.updateEmotionArray(emotionPost, emo_21to30);
					}else if(age<41){
						post_31to40++;
						cp.updateEmotionArray(emotionPost, emo_31to40);
					}else if(age<51){
						post_41to50++;
						cp.updateEmotionArray(emotionPost, emo_41to50);
					}else{
						post_more50++;
						cp.updateEmotionArray(emotionPost, emo_more50);
					}
				}
				}
			}
			Main.print += "----------AGE-----------\n";
			cp.normalizeListPostEm(emo_less21, post_less21);
			cp.normalizeListPostEm(emo_21to30, post_21to30);
			cp.normalizeListPostEm(emo_31to40, post_31to40);
			cp.normalizeListPostEm(emo_41to50, post_41to50);
			cp.normalizeListPostEm(emo_more50, post_more50);			
		}
}
